package com.usian.wemedia.service.impl;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.model.media.pojos.WmNews;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.mapper.WmUserMapper;
import com.usian.wemedia.service.WmUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class WmUserServiceImpl extends ServiceImpl<WmUserMapper, WmUser> implements WmUserService {
    @Override
    public WmUser insert(WmUser wmUser) {
        if (wmUser==null){
            return null;
        }
        wmUser.setCreatedTime(new Date());
        boolean b = this.save(wmUser);
        if (b){
            return wmUser;
        }else {
            return null;
        }
    }

    @Override
    public WmUser findByName(String name) {
        if (StringUtils.isBlank(name)){
            return null;
        }
        List<WmUser> list = this.list(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));

        if (list.size()>0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public WmUser findByUserId(Integer userId) {
        return this.getById(userId);
    }
}
